﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog x-modal-dialog" style="width:600px; margin-top: 150px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire" title="团课排期"></i>&nbsp;&nbsp;团课排期</h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/group-rounds/${courseRound.code}/arrange" data-validate="true">
      
     <input type="hidden" name="_method" value="PATCH">
     <input type="hidden" name="dayhour">
    
      <div class="modal-body">
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">开始时间</label>
          <div class="pull-left col-xs-6">
            <input type="text" class="form-control date" name="beginDate" value="" data-validate="required"/>
          </div>
        </div>
        
        <c:set var="step" value="${courseRound.course.hours / courseRound.course.weeks}"></c:set>
        
        <c:forEach begin="1" end="${step}" varStatus="i">
            
          <div class="form-group x-form-group">
            <label class="col-xs-3 control-label">每周</label>
            <div class="pull-left col-xs-4">
              <select name="day" class="form-control" data-validate="required">
                <option value=""></option>
                <option value="0">周一</option>
                <option value="1">周二</option>
                <option value="2">周三</option>
                <option value="3">周四</option>
                <option value="4">周五</option>
                <option value="5">周六</option>
                <option value="6">周日</option>
              </select>
            </div>
            <div class="pull-left col-xs-4">
              <select name="hours" class="form-control" data-validate="required">
                <option value=""></option>
                <c:forEach begin="${courseRound.site.appointStart[0]}" end="${courseRound.site.appointEnd[0]-1}" varStatus="status">
                  <c:set var="hour" value="${status.index}:00"></c:set>
                  <c:set var="halfhour" value="${status.index}:30"></c:set>
                  <c:choose>
                    <c:when test="${status.index == courseRound.site.appointStart[0] and courseRound.site.appointStart[1] == '30'}">
                      <option value="${halfhour}" ${schedule.occurHour eq halfhour ? 'selected' : ''}>${status.index}:30 ~ ${status.index + 1}:30</option>
                    </c:when>
                    <c:when test="${status.index == courseRound.site.appointEnd[0]-1 and courseRound.site.appointEnd[1] == '00'}">
                      <option value="${hour}" ${schedule.occurHour eq hour ? 'selected' : ''}>${status.index}:00 ~ ${status.index + 1}:00</option>
                    </c:when>
                    <c:otherwise>
                      <option value="${hour}" ${schedule.occurHour eq hour ? 'selected' : ''}>${status.index}:00 ~ ${status.index + 1}:00</option>
                      <option value="${halfhour}" ${schedule.occurHour eq halfhour ? 'selected' : ''}>${status.index}:30 ~ ${status.index + 1}:30</option>
                    </c:otherwise>
                  </c:choose>
                </c:forEach>
              </select>
            </div>
          </div>
          
        </c:forEach>
        
      </div>
      
      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>
    $('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        startDate: '${today}',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month'
      })
  
    $('select[name="day"]').select2({
      placeholder : '请选择每周几',
      minimumResultsForSearch : 5,
      allowClear : true,
    });
    
    $('select[name="hours"]').select2({
      placeholder : '请选择具体时间段',
      minimumResultsForSearch : 5,
      allowClear : true,
    });

</script>
